<template>
  <el-card style="min-height: 80vh;">
  <my-table path="teacher/" :cols="cols" :formObj="form" :tableAttrs="tableAttrs" :rules="rules"   >
    <template v-slot:form>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="form.name" placeholder="姓名" clearable></el-input>
      </el-form-item>
      <el-form-item label="用户名" prop="username" >
        <el-input v-model="form.username" placeholder="用户名" clearable></el-input>
      </el-form-item>
    </template>
  </my-table>
</el-card>
</template>

<script>
  import myTable from '../../components/myTable.vue';
  export default {
    components:{
      myTable
    },
    data() {
      var xingming = (rule, value, callback) => {
        var re = /^[\u4E00-\u9FA5A-Za-z0-9]+$/;
        let reT = /^.{2,10}$/;
        var reF = /^\d+$/;
        if (!re.test(value)) {
          callback(new Error('请输入中文、英文、数字但不包括下划线等符号!'));
        } else if (!reT.test(value)) {
          callback(new Error('姓名至少有2个字符，至多10个字符！'));
        } else if (reF.test(value)) {
          callback(new Error('姓名不能为纯数字'));
        } else {
          callback();
        }
      };
      var yonghu = (rule, value, callback) => {
        var re = /^[\u4E00-\u9FA5A-Za-z0-9]+$/;
        let reT = /^.{2,10}$/;
        var reF = /^\d+$/;
        if (!re.test(value)) {
          callback(new Error('请输入中文、英文、数字但不包括下划线等符号!'));
        } else if (!reT.test(value)) {
          callback(new Error('用户名至少有2个字符，至多10个字符！'));
        } else {
          callback();
        }
      };
      return {

        cols:[
          {
            property:'name',
            label:'姓名',
          },
          {
            property:'username',
            label:'用户名'
          }
        ],
        tableAttrs: {
          border: true
        },
       form: {
         name: '',
         username: '',
       },
 //对话框
        rules: {
          name: [{
            // required: true,
            message: '姓名必填',
            trigger: 'blur'
          },
          {
            validator: xingming,
            trigger: "blur"
          }
          ],
          username: [{
            // required: true,
            message: '用户名必填',
            trigger: 'blur'
          },
          {
            validator: yonghu,
            trigger: "blur"
          }],
        },
      }
    },
  }
</script>

<style>
</style>
